package com.example.appusagestats.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.appusagestats.R
import com.example.appusagestats.model.UsageEvent

class UsageDetailAdapter(
    private var usageEvents: List<UsageEvent>
) : RecyclerView.Adapter<UsageDetailAdapter.ViewHolder>() {

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val startTime: TextView = view.findViewById(R.id.startTime)
        val endTime: TextView = view.findViewById(R.id.endTime)
        val duration: TextView = view.findViewById(R.id.duration)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_usage_detail, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val event = usageEvents[position]
        
        holder.startTime.text = event.getFormattedStartTime()
        holder.endTime.text = event.getFormattedEndTime()
        holder.duration.text = event.getFormattedDuration()
    }

    override fun getItemCount() = usageEvents.size

    fun updateData(newEvents: List<UsageEvent>) {
        usageEvents = newEvents
        notifyDataSetChanged()
    }
} 